<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="okhttp3.*" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.concurrent.TimeUnit" %>
<%--获取流水号--%>
<%

    JSONObject paramJson = new JSONObject();
    String url = "https://a8.fway.vip/prod-api/task/dataSaveFromOA";
    String requestid = Util.null2String(request.getParameter("requestid"));
    String type = Util.null2String(request.getParameter("type"));
    String typeMemo = Util.null2String(request.getParameter("typeMemo"));
    paramJson.put("requestid", requestid);
    paramJson.put("type", type);
    paramJson.put("typeMemo", typeMemo);
    JSONObject resultJson = sendOKHttpRequest(url, paramJson.toJSONString());
    out.print(resultJson.toJSONString());
%>
<%!
    private static JSONObject sendOKHttpRequest(String url, String params) {
        JSONObject resultJson = new JSONObject();
        String message = "";
        String data = "";
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .connectTimeout(60, TimeUnit.SECONDS)
                    .readTimeout(60, TimeUnit.SECONDS)
                    .writeTimeout(60, TimeUnit.SECONDS)
                    .build();
            MediaType mediaType = MediaType.parse("text/plain");
            RequestBody body = RequestBody.create(mediaType, params);
            Request request = new Request.Builder()
                    .url(url)
                    .method("POST", body)
                    .build();
            Response response = client.newCall(request).execute();
            String result = Util.null2String(response.body().string());
            if (!"".equals(result)) {
                data = result;
                message = "success";
            } else {
                message = "response result is null";
            }
        } catch (Exception e) {
            message = "response timeout";
            e.printStackTrace();
        }
        resultJson.put("data", data);
        resultJson.put("message", message);
        return resultJson;
    }
%>